///////////////////////////////////////
//    Autor: Mato Kormuth              //
//    (C) Mato Programs 2011        //
//////////////////////////////////////
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace MBMC_Installation
{
    public partial class Paths : Form
    {
        string[] items;
        bool audacity;
        bool gimp;
        bool mbmc;
        bool oldversion;
        bool updater;
        public Paths(string[] array, ListBox.ObjectCollection coll)
        {
            InitializeComponent();
            items = array;
            //listBox1.Items = coll;
            foreach (object obj in coll)
            {
                listBox1.Items.Add(obj);
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            //Zacni instalovat
            //Instalacny script
            //MBMC OLDVERSION
            backgroundWorker1.ReportProgress(2);
            if (oldversion == true)
            {
                System.Diagnostics.Process p = new System.Diagnostics.Process();
                backgroundWorker1.ReportProgress(4);
                p.StartInfo.FileName = Application.StartupPath + "data/Setup.exe";
                MessageBox.Show("Installation detected MBMC 0.2.1 setup in data folder. When you finish install(must be in folder you specified) click on OK!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                backgroundWorker1.ReportProgress(15);
                listBox2.Items.Add(new StringBuilder("Audacity Plugin/Standalone with all plugins").ToString());
            }
            if (mbmc == true)
            {
                //Skopiruj instalacku z winraru do textbox.text a pusti ju v tom priecinku
                //Marble Blast Mods Creator 0.2.2 Patch 1
                backgroundWorker1.ReportProgress(17);
                System.IO.File.Copy(Application.StartupPath + "/data/mbmc.data", textBox1.Text + "/mbmc.exe");
                backgroundWorker1.ReportProgress(25);
                System.Diagnostics.Process p = new System.Diagnostics.Process();
                p.StartInfo.FileName = textBox1.Text + "/mbmc.exe";
                p.StartInfo.WorkingDirectory = textBox1.Text;
                backgroundWorker1.ReportProgress(26);
                p.Start();
                backgroundWorker1.ReportProgress(35);
                System.IO.File.Delete(textBox1.Text + "/mbmc.exe");
                listBox2.Items.Add(new StringBuilder("Marble Blast Mods Creator 0.2.2 Patch 1").ToString());
            }
            if (updater == true)
            {
                //Skopiruj instalacku z winraru do textbox.text a pusti ju
                //updater.exe
                //Marble Blast Mods Creator Updater 0.0.2 BETA
                backgroundWorker1.ReportProgress(37);
                System.IO.File.Copy(Application.StartupPath + "/data/updater.exe", textBox1.Text + "/updater.exe");
                backgroundWorker1.ReportProgress(40);
                System.Diagnostics.Process p = new System.Diagnostics.Process();
                p.StartInfo.FileName = textBox1.Text + "/updater.exe";
                p.StartInfo.WorkingDirectory = textBox1.Text;
                backgroundWorker1.ReportProgress(41);
                p.Start();
                backgroundWorker1.ReportProgress(50);
                System.IO.File.Delete(textBox1.Text + "/updater.exe");
                listBox2.Items.Add(new StringBuilder("Marble Blast Mods Creator Updater 0.0.2 BETA").ToString());

            }
            if (gimp == true)
            {
                //Skopiruj instalacku z winraru do textbox.text/data/apps/gimp/ a pusti ju
                //gimp.exe
                //GIMP 2.6.11 Plugin/Standalone
                backgroundWorker1.ReportProgress(51);
                System.IO.File.Copy(Application.StartupPath + "/data/gimp.exe", textBox1.Text + "/data/apps/gimp/gimp.exe");
                backgroundWorker1.ReportProgress(57);
                System.Diagnostics.Process p = new System.Diagnostics.Process();
                p.StartInfo.FileName = textBox1.Text + "/data/apps/gimp/gimp.exe";
                p.StartInfo.WorkingDirectory = textBox1.Text;
                backgroundWorker1.ReportProgress(65);
                p.Start();
                backgroundWorker1.ReportProgress(80);
                System.IO.File.Delete(textBox1.Text + "/data/apps/gimp/gimp.exe");
                listBox2.Items.Add(new StringBuilder("GIMP 2.6.11 Plugin/Standalone").ToString());
                backgroundWorker1.ReportProgress(90);
            }
            if (audacity == true)
            {
                //Skopiruj instalacku z winraru do textbox.text/data/apps/gimp/ a pusti install.bat
                //Vynechane
            }
            System.Diagnostics.Process pf = new System.Diagnostics.Process();
            pf.StartInfo.FileName = textBox1.Text + "/MBMC.exe";
            pf.StartInfo.WorkingDirectory = textBox1.Text;
            pf.StartInfo.Arguments = "-install";
            backgroundWorker1.ReportProgress(95);
            MessageBox.Show("Now you must config mbmc settings, is highly recommended to configure them!", "!!!INFORMATION!!!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            pf.Start();
            backgroundWorker1.ReportProgress(100);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            button1.Enabled = false;
            button2.Enabled = false;
            button3.Enabled = false;
            textBox1.Enabled = false;
            backgroundWorker1.RunWorkerAsync();
        }

        private void Paths_Load(object sender, EventArgs e)
        {
            foreach (string obj in items)
            {
                if (obj == "audacity")
                {
                    audacity = true;
                }
                if (obj == "gimp")
                {
                    gimp = true;
                }
                if (obj == "oldversion")
                {
                    oldversion = true;
                }
                if (obj == "mbmc")
                {
                    mbmc = true;
                }
                if (obj == "updater")
                {
                    updater = true;
                }
            }
        }

        private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            //Finished
            MessageBox.Show("Completed!");
        }

        private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            progressBar1.Value = e.ProgressPercentage;
        }
    }
}